<script lang="ts" setup>
  const props = defineProps({
    title: {
      type: String,
      default: '更改创建人'
    }
  })
  defineOptions({ name: 'EUpdateCreators' })

  const userId = ref<string>('')
  const userInfo = ref<any>({})

  const handleUpdateValueModel = (data: any) => {
    userInfo.value = data
  }

  // 弹窗
  const dialogVisible = ref<boolean>(false)
  const openDialog = () => {
    dialogVisible.value = true
    userId.value = ''
    userInfo.value = {}
  }

  const emit = defineEmits(['confirm'])
  // 确定
  const handleSubmit = () => {
    if (!userId.value) return ElMessage.error('请选择人员信息')
    dialogVisible.value = false
    emit('confirm', userId.value, userInfo.value)
  }
  // 取消
  const handleCancel = () => {
    dialogVisible.value = false
  }
  // 暴露方法
  defineExpose({
    openDialog
  })
</script>
<template>
  <Dialog v-model="dialogVisible" :title="props.title" width="500px">
    <e-remote-select
      v-bind="$attrs"
      v-model.sync="userId"
      @update:value-model="handleUpdateValueModel"
    />
    <template #footer>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
      <el-button @click="handleCancel">取消</el-button>
    </template>
  </Dialog>
</template>
